package com.hmall.order.service.impl;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.common.feign.SearchClient;
import com.hmall.order.mapper.OrderMapper;
import com.hmall.order.pojo.Order;
import com.hmall.order.pojo.OrderDetail;
import com.hmall.order.service.IOrderService;
import com.hmall.order.service.IOrderdetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService extends ServiceImpl<OrderMapper, Order> implements IOrderService {
    @Autowired
    private IOrderService orderService;
    @Autowired
    private IOrderdetailService iOrderdetailService;
    @Autowired
    private SearchClient searchClient;


    @Override
    public void updateByIds(Long id) {
        Order order = orderService.getById(id);

        LambdaUpdateWrapper<OrderDetail> qw = new LambdaUpdateWrapper<>();
        qw.eq(OrderDetail::getOrderId,order.getId());
        OrderDetail orderDetail = iOrderdetailService.getOne(qw);


        if(order.getStatus()==1){
            LambdaUpdateWrapper<Order> qw2 = new LambdaUpdateWrapper<>();
            qw2.set(Order::getStatus, 5);
            qw2.in(Order::getId,order.getId());
            orderService.update(qw2);
            searchClient.updateStockRecover(orderDetail.getItemId(),orderDetail.getNum());


        }

    }
}
